<?php
namespace app\posts\controller;
use app\forum\controller\SiteController;
/**
 * 板块页面
 */

class PlateController extends SiteController {

	/**
     * 板块页
     */
    public function index(){
    	$plateId = request('get.plate_id',0,'intval');
        if (empty($plateId)) {
            $this->error404();
        }
        //获取板块信息
        $model = target('forum/Plate');
        if(!empty($plateId)){
            $plateInfo = $model->getInfo($plateId);
        }else{
            $this->error404();
        }
        //信息判断
        if(empty($plateInfo) || strtolower($plateInfo['app'])<>APP_NAME){
            $this->error404();
        }
        //检测权限
        $this->checkForumPurview($plateId,'view');
        //位置导航
        $crumb = target('forum/Plate')->loadCrumb($plateId);
        $this->crumb = array_merge($this->crumb,$crumb);
        //MEDIA信息
        $media = $this->getMedia($plateInfo['name'],$plateInfo['keywords'],$plateInfo['description']);

        //获取板块类型
        $subList = target('forum/Plate')->getSubPlate($plateId);
        if(!$plateInfo['parent_id'] || $subList){
            $plateList = $subList;
            $this->assign('plateList', $plateList);
        }else{
            //设置查询条件
            $where = array();
            $where['A.status'] = 1;
            $where['A.type_top'] = 0;
            $where[] = 'C.plate_id in ('.$plateInfo['plate_id'].')';
            //查询内容数据
            $modelThread = target('ThreadPosts');
            if(!empty($plateInfo['content_order'])){

                $plateInfo['content_order'] = $plateInfo['content_order'].',';
            }
            $pageList = $modelThread->page(20)->loadList($where,$limit,$plateInfo['content_order'].'A.post_time desc,A.thread_id desc');
            $this->pager = $modelThread->pager;
            //URL参数
            $pageMaps = array();
            $pageMaps['plate_id'] = $plateId;
            //获取分页
            $page = $this->getPageShow($pageMaps);
            $this->assign('pageList', $pageList);
            $this->assign('page', $page);
            $this->assign('pageMaps', $pageMaps);
            $this->assign('topList', target('forum/Thread')->getTopList($plateId));
        }
        //模板赋值
        $this->assign('plateInfo', $plateInfo);
        $this->assign('media', $media);
        $this->siteDisplay();
    }
}